package com.hisense.ovcloud.apicontrol.service;

import com.hisense.ovcloud.apicontrol.dto.req.ValidateReq;
import com.hisense.ovcloud.apicontrol.dto.resp.TokenRes;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

@Slf4j
@Service
public class TokenAuthService {
    private final AccessTokenCheckService accessTokenCheckService;

    private final ApplianceTokenCheckService applianceTokenCheckService;

    public TokenAuthService(AccessTokenCheckService accessTokenCheckService, ApplianceTokenCheckService applianceTokenCheckService) {
        this.accessTokenCheckService = accessTokenCheckService;
        this.applianceTokenCheckService = applianceTokenCheckService;
    }

    public Mono<TokenRes> tokenAuth(String path, String accessToken){
        if(accessTokenCheckService.shouldFilter(ValidateReq.builder().path(path).build())){
            return accessTokenCheckService.tokenAuth(path, accessToken);
        } else if (applianceTokenCheckService.shouldFilter(ValidateReq.builder().path(path).build())) {
            return applianceTokenCheckService.tokenAuth(accessToken);
        }else{
            return Mono.just(TokenRes.builder().build());
        }
    }
}
